package com.kefu.call.vo;

import javax.persistence.Column;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.kefu.call.model.ContactPlan;
import org.apache.commons.lang3.StringUtils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.kefu.common.context.KefuContext;
import com.kefu.common.vo.AbstractSearchVo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import java.util.Objects;

/**
 * @author francis
 * @date 2021/05/22
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@ApiModel(description = "联系计划")
public class ContactPlanSearchVo extends AbstractSearchVo {
	/**
	 * 计划名称
	 */
    @ApiModelProperty(value = "计划名称")
    private String planName;
	/**
	 * 预约起始时间
	 */
	@ApiModelProperty(name = "subscribeTimeStart", value = "预约起始时间")
	private Long subscribeTimeStart;
	/**
	 * 预约结束时间
	 */
	@ApiModelProperty(name = "subscribeTimeEnd", value = "预约起始时间")
	private Long subscribeTimeEnd;

	/**
	 * 创建起始时间
	 */
	@ApiModelProperty(name = "createTimeStart", value = "创建起始时间")
	private Long createTimeStart;
	/**
	 * 创建结束时间
	 */
	@ApiModelProperty(name = "createTimeEnd", value = "创建结束时间")
	private Long createTimeEnd;
	/**
	 * 计划状态
	 */
	@ApiModelProperty(value = "计划状态")
    private Integer planStatus;
	/**
	 * 手机号码
	 */
	@ApiModelProperty(value = "手机号码")
    private String customerPhone;
	/**
	 * 计划来源
	 */
    @ApiModelProperty(value = "计划来源",notes="1=自建，2=在线留言，3=呼叫留言")
    private Integer planType;

	@Override
	public LambdaQueryWrapper lambdaQuery() {
		LambdaQueryWrapper<ContactPlan> wrapper = Wrappers.lambdaQuery(ContactPlan.class);
		if (StringUtils.isNotBlank(planName)) {
			wrapper.like(ContactPlan::getPlanName, planName);
		}
		if (planStatus != null) {
			wrapper.eq(ContactPlan::getPlanStatus, planStatus);
		}
		if (StringUtils.isNoneBlank(customerPhone)) {
			wrapper.eq(ContactPlan::getCustomerPhone, customerPhone);
		}
		if (planType != null) {
			wrapper.eq(ContactPlan::getPlanType, planType);
		}
		if (Objects.nonNull(createTimeStart)) {
			wrapper.ge(ContactPlan::getCreateTime, createTimeStart);
		}
		if (Objects.nonNull(createTimeEnd)) {
			wrapper.le(ContactPlan::getCreateTime, createTimeEnd);
		}
		if (Objects.nonNull(subscribeTimeStart)) {
			wrapper.ge(ContactPlan::getSubscribeTime, subscribeTimeStart);
		}
		if (Objects.nonNull(subscribeTimeEnd)) {
			wrapper.le(ContactPlan::getSubscribeTime, subscribeTimeEnd);
		}
		wrapper.eq(ContactPlan::getCreateUser, KefuContext.getUid());
		wrapper.eq(ContactPlan::getDataStatus, 1);
		wrapper.eq(ContactPlan::getTenantId, KefuContext.getKefuContext().getTenantId());
		wrapper.orderByDesc(ContactPlan::getCreateTime);
		return wrapper;
	}
}